package com.ruoyi.web.zangchat.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.web.zangchat.domain.dto.ChatTrendsDTO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.zangchat.domain.ChatTrends;
import com.ruoyi.web.zangchat.service.IChatTrendsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 广场动态Controller
 * 
 * @author ruoyi
 * @date 2020-07-22
 */
@Controller
@RequestMapping("/zangchat/chatTrends")
public class ChatTrendsController extends BaseController
{
    private String prefix = "zangchat/chatTrends";

    @Autowired
    private IChatTrendsService chatTrendsService;

    @RequiresPermissions("zangchat:chatTrends:view")
    @GetMapping()
    public String chatTrends()
    {
        return prefix + "/chatTrends";
    }

    /**
     * 查询广场动态列表
     */
    @RequiresPermissions("zangchat:chatTrends:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String,Object> map)
    {
        startPage();
        return getDataTable(chatTrendsService.chatTrendsList(map));
    }

    /**
     * 导出广场动态列表
     */
    @RequiresPermissions("zangchat:chatTrends:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ChatTrends chatTrends)
    {
        List<ChatTrends> list = chatTrendsService.list(new QueryWrapper<>());
        ExcelUtil<ChatTrends> util = new ExcelUtil<ChatTrends>(ChatTrends.class);
        return util.exportExcel(list, "chatTrends");
    }

    /**
     * 新增广场动态
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存广场动态
     */
    @RequiresPermissions("zangchat:chatTrends:add")
    @Log(title = "广场动态", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ChatTrends chatTrends)
    {
        return toAjax(chatTrendsService.save(chatTrends));
    }

    /**
     * 修改广场动态
     */
    @GetMapping("/edit/{trendsId}")
    public String edit(@PathVariable("trendsId") Long trendsId, ModelMap mmap)
    {
//        ChatTrends chatTrends = chatTrendsService.getById(trendsId);
//        Map<String,Object> chatTrends = chatTrendsService.getMapById(trendsId);
        ChatTrendsDTO chatTrends = chatTrendsService.getDTOById(trendsId);
        mmap.put("chatTrends", chatTrends);
        return prefix + "/edit";
    }

    /**
     * 修改保存广场动态
     */
    @RequiresPermissions("zangchat:chatTrends:edit")
    @Log(title = "广场动态", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ChatTrends chatTrends)
    {
        return toAjax(chatTrendsService.updateById(chatTrends));
    }

    /**
     * 删除广场动态
     */
    @RequiresPermissions("zangchat:chatTrends:remove")
    @Log(title = "广场动态", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
       ;
//        return toAjax(chatTrendsService.removeByIds(Arrays.asList(Convert.toStrArray(ids))));
        return toAjax(chatTrendsService.deleteByIds(ids));
    }
}
